﻿@using LunwenYun.Infrastructure.Entities.Entity;
@using LunwenYun.Infrastructure.Entities.Enum;
@{
    Layout = "~/Views/Shared/_o_Main.cshtml";
    User user = new User().Find(HttpContext.Current.User.Identity.Name);
}
<div class="container">
    <div style="display: none;">
        <form id="form1" action="/o/industryorderOption" method="post">
        <input id="hidtoken" type="hidden" name="Token" />
        <input id="hidprice" type="hidden" name="Price" />
        <input id="hidOptionType" type="hidden" name="OptionType" />
        <input id="hidId" type="hidden" name="Id" />
        </form>
    </div>
    <div class="row">
        <div class="span3">
            <ul class="nav nav-tabs nav-stacked">
                <li class="active"><a href="/o/authorcenter"><i class="icon-user"></i><strong>个人中心</strong></a></li>
                <li><a href="/o/authorcenter">约稿稿件</a></li>
                <li><a href="/o/myorders">我的约稿
                    @if (ViewBag.OrderCount > 0)
                    {
                        <span class="badge badge-warning">@ViewBag.OrderCount</span>
                    }</a></li>
                @if (user.Industry > 0)
                {
                    <li class="active"><a href="/o/industryorders">我的行业约稿</a></li>
                }
                <li><a href="/o/profile">约稿人信息</a></li>
                <li><a href="/o/resetpassword">修改密码</a></li>
            </ul>
        </div>
        <div class="span9">
            <blockquote>
                <p>
                    <strong>我的行业约稿</strong></p>
            </blockquote>
            <hr />
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>
                            投稿行业
                        </th>
                        <th style="width: 15%">
                            投稿人
                        </th>
                        <th style="width: 20%">
                            投稿时间
                        </th>
                        <th style="width: 8%">
                            状态
                        </th>
                        <th style="width: 25%">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @{
                        ItemListBox<Trade> list = ViewBag.Orders;
                        if (list != null && list.Data != null && list.Data.Any())
                        {
                            foreach (var item in list.Data)
                            {
                        <tr>
                            <td>
                                @ViewBag.IndustryName
                            </td>
                            <td>@item.ConsumerName
                            </td>
                            <td>@item.OpenDate.ToString("yyyy-MM-dd HH:mm")
                            </td>
                            <td>
                                @switch (item.Status)
                                {
                                    default:
                                    case TradeStatus.Open:
                                    case TradeStatus.Execute:
                                    case TradeStatus.TradeConfirm_o:
                                    <span class="label label-info"><b>@item.Status.Mapping()</b> </span>
                                                                 break;
                                    case TradeStatus.Pay:
                                    <span class="label label-warning"><b>@item.Status.Mapping()</b> </span>   
                                                                    break;
                                    case TradeStatus.WaitPay:
                                    <span class="label label-warning"><b>@item.Status.Mapping()</b> </span>   
                                                                    break;
                                    case TradeStatus.TradeIsConfirm:
                                    case TradeStatus.Trading:
                                    <span class="label label-success"><b>@item.Status.Mapping()</b> </span> 
                                                                    break;
                                    case TradeStatus.Cancel:
                                    <span class="label"><b>@item.Status.Mapping()</b></span>
                                                      break;
                                    case TradeStatus.Dispute:
                                    <span class="label label-important"><b>@item.Status.Mapping()</b></span>
                                                                      break;
                                }
                            </td>
                            <td>
                                <a href="javascript:;" onclick="opendetail(this)" class="btn btn-mini">详情</a>
                                @if (item.Status == TradeStatus.Open)
                                {
                                    
                                    <div class="btn-group btn-mini">
                                        <button class="btn btn-primary btn-mini" onclick="acceptorder(@item.Id,'@item.Token')">
                                            接收</button>
                                        <button data-toggle="dropdown" class="btn btn-primary btn-mini dropdown-toggle">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="javascript:;" onclick="refuseorder(@item.Id,'@item.Token')">取消</a></li>
                                            <li><a href="javascript:;" onclick="deleteorder(@item.Id,'@item.Token')">删除</a></li>
                                        </ul>
                                    </div>
                                }
                                else
                                {
                                    <span class="label label-success">@item.SupplierName 已接收处理</span>
                                }
                            </td>
                        </tr>
                        <tr style="display: none;">
                            <td colspan="5">@Html.Raw(item.Description)
                                <br />
                                <p>
                                    预算金额：<b>@((int)item.Momey)</b></p>
                                @if (item.Status == TradeStatus.TradeConfirm_o)
                                {
                                    <p>
                                        已于 @item.ConfirmTradeDate.ToString("yyyy/MM/dd HH:mm") 确认该稿件已发表，请耐心等待投稿人的确认。也可以立即联系投稿人并要求其进行确认。
                                        如投稿人在 @item.ConfirmExpireDate.ToString("yyyy/MM/dd 23:59") 后任未确认，系统将自动确认本次约稿完成。
                                    </p>
                                }
                            </td>
                        </tr>
                            }
                        }}
                </tbody>
            </table>
        </div>
    </div>
</div>
@section tail
{
<script type="text/javascript" src="/Scripts/plug.js"></script>
    <script type="text/javascript">
        var instance = new plug.MessageBox();
        $(function () {
            $('#licenter').addClass('active');
        });
        function opendetail(sender) {
            $(sender).parent().parent().next('tr').toggle();
        }
        function acceptorder(id, token) {
            instance.Show('<div class="control-group"><label class="control-label" >请输入约稿预算金额：</label><div class="controls"><input type="text" id="txtprice"></div></div>',
                '<a href="javascript:;" class="btn btn-primary btn-mini" onclick="confirmaccept(\'txtprice\','+id+',\''+token+'\')">确定</a>',
                '<a href="javascript:;" id="btnclose" style="margin-left:10px;" class="btn btn-mini">取消</a>',
                'btnclose');
           
        }
        function confirmaccept(txtId, id, token) {
            var price = $('#' + txtId).val();
            if (!/^\d+(\.\d+)?$/g.test(price)) {
                alert('金额输入有误，请重新输入');
                $('#' + txtId).val('');
                $('#' + txtId).focus();
                return;
            }
            if (confirm('您确定接收此次约稿吗？')) {
                $('#hidOptionType').val(1);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#hidprice').val(price);
                $('#form1').submit();
            }
        }
        function refuseorder(id, token) {
            if (confirm('您确定取消此次约稿吗？')) {
                $('#hidOptionType').val(2);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
        function deleteorder(id, token) {
            if (confirm('您确定删除此约稿信息吗？')) {
                $('#hidOptionType').val(9);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
    </script>
}
